package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.MemberVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "管理端-设备管理")
@RestController
@RequestMapping("/iot")
public class DeviceController {


    @Autowired
    DeviceService deviceService;


    /**
     * 同步产品列表的接口
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation(value = "同步产品列表",notes = "同步产品列表")
    public ResponseResult syncProduct(){
        deviceService.syncProduct();
        return ResponseResult.success();
    }

    /**
     * 查询所有产品列表
     * 接口地址:/iot/allProduct
     * 请求方式:GET
     * 请求参数:无
     */
    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表",notes = "查询所有产品列表")
    public ResponseResult allProduct(){
        List<ProductVo> productVoList = deviceService.allProduct();
        return ResponseResult.success(productVoList);
    }




    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备",notes = "注册设备")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);

        return ResponseResult.success();
    }



    @ApiOperation(value = "分页查询设备信息", notes = "根据页码、" +
            "每页数量、设备名称，产品key，设备类型分页查询设备信息")
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> page(DevicePageQueryDto devicePageQueryDto) {
        PageResponse<DeviceVo> pageResponse = deviceService.page(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }



    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详情",notes = "查询设备详情")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

//    接口地址:/iot/QueryThingModelPublished
//    请求方式:POST
//    请求示例:
//    {
//        "productKey": "j0rk7e6hJkx"
//    }
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查询指定产品已发布的物模型",notes = "查询指定产品已发布的物模型")
    public ResponseResult<String> queryThingModelPublished(@RequestBody DeviceDto deviceDto){

        return deviceService.queryThingModelPublished(deviceDto);
    }


    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态",notes = "查询指定设备的物模型运行状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto){


        return   deviceService.queryDevicePropertyStatus(deviceDto);
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备备注名称")
    public ResponseResult<Void> batchUpteDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

}
